﻿using System;
using Autodesk.Revit.DB;
using YArchitech.Revit;

namespace YArchitech.DataModel
{
	public class SetParaForInstance
	{
		public static void SetOffsetForInstance(Element elem, double offset, Autodesk.Revit.DB.Document doc)
		{
			Parameter parameter = null;
			Parameter parameter2 = null;
			double num = 0.0;
			if (elem.GetParameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM) != null)
			{
				parameter2 = elem.GetParameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM);
			}
			else
			{
				Parameter parameter3 = elem.GetParameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
				if (parameter3 != null)
				{
					parameter3.Set(doc.ActiveView.GenLevel.Id);
				}
			}
			if (parameter2 != null)
			{
				parameter2.Set(UnitConvert.CovertToAPI(offset * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)2));
				num = parameter2.AsDouble();
			}
			if (num != UnitConvert.CovertToAPI(offset * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)2))
			{
				if (elem.GetParameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM) != null)
				{
					parameter = elem.GetParameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
				}
				if (parameter != null)
				{
					parameter.Set(UnitConvert.CovertToAPI(offset * 1000.0, (Autodesk.Revit.DB.DisplayUnitType)2));
				}
			}
		}
	}
}
